package main

import (
    "fmt"
    "math/rand"
    "time"
)

// Skill 技能接口
type Skill interface {
    Execute(caster string, target string) string
    GetSkillName() string
    GetCooldown() time.Duration
    GetManaCost() int
}

// SkillCreator 技能创建者接口（抽象创建者）
type SkillCreator interface {
    CreateSkill(level int, attributes map[string]int) Skill
    GetSkillType() string
    CanCreate(level int) bool
}

// AttackSkill 攻击技能
type AttackSkill struct {
    Name     string
    Damage   int
    Cooldown time.Duration
    ManaCost int
}

func (a *AttackSkill) Execute(caster string, target string) string {
    actualDamage := a.Damage + rand.Intn(10)
    return fmt.Sprintf("%s 对 %s 使用了 %s，造成 %d 点伤害", 
        caster, target, a.Name, actualDamage)
}

func (a *AttackSkill) GetSkillName() string {
    return a.Name
}

func (a *AttackSkill) GetCooldown() time.Duration {
    return a.Cooldown
}

func (a *AttackSkill) GetManaCost() int {
    return a.ManaCost
}

// WarriorSkillCreator 战士技能创建者
type WarriorSkillCreator struct{}

func (w *WarriorSkillCreator) CreateSkill(level int, attributes map[string]int) Skill {
    strength := attributes["strength"]
    return &AttackSkill{
        Name:     fmt.Sprintf("战士斩击 Lv.%d", level),
        Damage:   20 + level*5 + strength*2,
        Cooldown: time.Second * time.Duration(5-level/5),
        ManaCost: 10 + level*2,
    }
}

func (w *WarriorSkillCreator) GetSkillType() string {
    return "战士技能"
}

func (w *WarriorSkillCreator) CanCreate(level int) bool {
    return level >= 1
}

// MageSkillCreator 法师技能创建者
type MageSkillCreator struct{}

func (m *MageSkillCreator) CreateSkill(level int, attributes map[string]int) Skill {
    intelligence := attributes["intelligence"]
    return &AttackSkill{
        Name:     fmt.Sprintf("火球术 Lv.%d", level),
        Damage:   15 + level*7 + intelligence*3,
        Cooldown: time.Second * time.Duration(3-level/10),
        ManaCost: 20 + level*3,
    }
}

func (m *MageSkillCreator) GetSkillType() string {
    return "法师技能"
}

func (m *MageSkillCreator) CanCreate(level int) bool {
    return level >= 1
}

// 使用演示
func main() {
    fmt.Println("=== 技能工厂演示 ===")
    rand.Seed(time.Now().UnixNano())
    
    // 创建技能创建者
    warriorCreator := &WarriorSkillCreator{}
    mageCreator := &MageSkillCreator{}
    
    creators := []SkillCreator{warriorCreator, mageCreator}
    
    // 角色属性
    warriorAttributes := map[string]int{"strength": 20, "intelligence": 8}
    mageAttributes := map[string]int{"strength": 8, "intelligence": 25}
    
    attributesList := []map[string]int{warriorAttributes, mageAttributes}
    
    for i, creator := range creators {
        fmt.Printf("=== %s 演示 ===\n", creator.GetSkillType())
        
        for level := 1; level <= 5; level += 2 {
            if creator.CanCreate(level) {
                skill := creator.CreateSkill(level, attributesList[i])
                result := skill.Execute(fmt.Sprintf("%s玩家", creator.GetSkillType()), "敌人")
                fmt.Printf("等级 %d: %s\n", level, result)
                fmt.Printf("冷却时间: %v, 法力消耗: %d\n", skill.GetCooldown(), skill.GetManaCost())
            }
        }
        fmt.Println()
    }
}